# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/12 22:24
# @Author   : Robot-Zsj
"""
description:

i:
5
/huawei/computing/no/one
/huawei/computing/
/huawei
/huawei/cloud/no/one
/huawei/wireless/no/one
2 computing
o:
2
"""

n = int(input())

cnts = []

for _ in range(n):

    urlComponents = input().split("/")

    for level in range(len(urlComponents)):
        urlComponent = urlComponents[level]

        if level >= len(cnts):
            cnts.append({})

        cnts[level][urlComponent] = cnts[level].get(urlComponent, 0) + 1

tar_level, tar_urlComponent = input().split()

tar_level = int(tar_level)

if tar_level >= len(cnts):
    print(0)
else:
    print(cnts[tar_level].get(tar_urlComponent, 0))
